//
//  TransferOpeningViewController.m
//  nonghubao
//
//  Created by Fenrir on 13-5-17.
//  Copyright (c) 2013年 Chongqing Nonghubao Co., Ltd. All rights reserved.
//

#import "TransferOpeningViewController.h"
#import "Helper.h"
#import "Config.h"
#import <QuartzCore/QuartzCore.h>
#import "RTLabel.h"
#import "JMFBase.h"


//  -业务逻辑细节说明-
//
//  @abstract       本类的业务逻辑较为简单，让用户填一系列的表单数据，再向服务器提交申请开通转账业务即可

//  @discussion
        
//  @notes          


//  -类修改日志-
//  修改人   修改时间   针对版本   修改描述

@interface TransferOpeningViewController ()

@end

@implementation TransferOpeningViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    [self banksRequest];
    UIButton *backButton = [Helper buttonWithStyle:ButtonStyleNavigationReturn];
    [backButton addTarget:self action:@selector(backButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    
    _scrollView = [[CustomScrollView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, _SYS_FRAME_HEIGHT)];
    _scrollView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"com_bg_012@2x" ofType:@"png"]]];
    _scrollView.customDelegate = self;
    _scrollView.showsVerticalScrollIndicator = NO;
    _scrollView.showsHorizontalScrollIndicator = NO;
    CGSize newSize = CGSizeMake(self.view.frame.size.width, _SYS_FRAME_HEIGHT + 320.0f);
    
    [_scrollView setContentSize:newSize];
    [self.view addSubview:_scrollView];
    
    //温馨提示view
    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 220.0f)];
    titleView.backgroundColor = [UIColor whiteColor];
    
    [_scrollView addSubview:titleView];
    
    //温馨提示
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(125.0f, 5.0f, 80.0f, 30.0f)];
    titleLabel.font = _SYS_FONT_005;
    titleLabel.text = _L(@"title_15");
    [titleView addSubview:titleLabel];
    
    //分割线
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, titleLabel.frame.origin.y + titleLabel.frame.size.height + 5.0f, 320.0f, 0.5f)];
    
    lineView.backgroundColor = [UIColor colorWithRed:219.0f/255.0f green:219.0f/255.0f blue:219.0f/255.0f alpha:1.0f];
    
    [titleView addSubview:lineView];
    
    //提示内容
    RTLabel *firstLabel = [[RTLabel alloc] initWithFrame:CGRectMake(10.0f, lineView.frame.origin.y + lineView.frame.size.height + 10.0f, 300.0f, 25.0f)];
    firstLabel.font = _SYS_FONT_005;
    firstLabel.text = [NSString stringWithFormat:_L(@"tpl_25"), TRANSFER_MIN_LIMIT];
    [titleView addSubview:firstLabel];
    
    RTLabel *secondLabel = [[RTLabel alloc] initWithFrame:CGRectMake(10.0f, firstLabel.frame.origin.y + firstLabel.frame.size.height, 300.0f, 25.0f)];
    secondLabel.font = _SYS_FONT_005;
    secondLabel.text = _L(@"tpl_26");
    [titleView addSubview:secondLabel];
    
    RTLabel *thirdLabel = [[RTLabel alloc] initWithFrame:CGRectMake(10.0f, secondLabel.frame.origin.y + secondLabel.frame.size.height, 300.0f, 38.0f)];
    thirdLabel.font = _SYS_FONT_005;
    thirdLabel.text = _L(@"tpl_27");
    [titleView addSubview:thirdLabel];
    
    UILabel *fourthLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, thirdLabel.frame.origin.y + thirdLabel.frame.size.height, 300.0f, 38.0f)];
    fourthLabel.font = _SYS_FONT_005;
    fourthLabel.numberOfLines = 0;
    thirdLabel.lineBreakMode = NSLineBreakByWordWrapping;
    fourthLabel.text = _L(@"tpl_28");
    [titleView addSubview:fourthLabel];
    
    UILabel *fifthLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, fourthLabel.frame.origin.y + fourthLabel.frame.size.height, 300.0f, 38.0f)];
    fifthLabel.font = _SYS_FONT_005;
    fifthLabel.numberOfLines = 0;
    fifthLabel.lineBreakMode = NSLineBreakByWordWrapping;
    fifthLabel.text = _L(@"tpl_29");
    [titleView addSubview:fifthLabel];
    
    //登录密码View
    UIView *passwordView = [self createCustomView:titleView andRow:1 andTitle:_L(@"title_54")];
    [_scrollView addSubview:passwordView];
    
    _passwordTextField = [[UITextField alloc] initWithFrame:CGRectMake(85, 12, 200, 24)];
    _passwordTextField.secureTextEntry = YES;
    _passwordTextField.tag = 101;
    _passwordTextField.returnKeyType = UIReturnKeyDone;
    _passwordTextField.font = _SYS_FONT_003;
    _passwordTextField.delegate = self;
//    _passwordTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    _passwordTextField.placeholder = _L(@"holder_18");
    [passwordView addSubview:_passwordTextField];
    
    
    //银行卡号View
    UIView *cardIdView = [self createCustomView:passwordView andRow:1 andTitle:_L(@"title_55")];
    [_scrollView addSubview:cardIdView];
    
    _cardIdTextField = [[UITextField alloc] initWithFrame:CGRectMake(85, 12, 200, 24)];
    _cardIdTextField.tag = 100;
    _cardIdTextField.keyboardType = UIKeyboardTypeNumberPad;
    _cardIdTextField.returnKeyType = UIReturnKeyDone;
    _cardIdTextField.font = _SYS_FONT_003;
    _cardIdTextField.delegate = self;
//    _cardIdTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    _cardIdTextField.placeholder = _L(@"holder_19");
    [cardIdView addSubview:_cardIdTextField];
    
    //开户银行View
    UIView *bankNameView = [self createCustomView:cardIdView andRow:1 andTitle:_L(@"title_56")];
    [_scrollView addSubview:bankNameView];
    
    _bankNameTextField = [[UITextField alloc] initWithFrame:CGRectMake(85, 12, 200, 24)];
    _bankNameTextField.tag = 99;
    _bankNameTextField.returnKeyType = UIReturnKeyDone;
    _bankNameTextField.font = _SYS_FONT_003;
    _bankNameTextField.delegate = self;
    _bankNameTextField.placeholder = _L(@"holder_20");  //在国际化文件里面修改为"请选择开户银行"
    [bankNameView addSubview:_bankNameTextField];
    
    //银行所在地View
    UIView *bankLocationView = [self createCustomView:bankNameView andRow:1 andTitle:_L(@"title_74")];
    [_scrollView addSubview:bankLocationView];
    
    _bankLocationTextField = [[UITextField alloc] initWithFrame:CGRectMake(85, 12, 200, 24)];
    _bankLocationTextField.tag = 98;
    _bankLocationTextField.returnKeyType = UIReturnKeyDone;
    _bankLocationTextField.font = _SYS_FONT_003;
    _bankLocationTextField.delegate = self;
    _bankLocationTextField.placeholder = _L(@"holder_31");
    [bankLocationView addSubview:_bankLocationTextField];
    
    //开户支行View
    UIView *branchView = [self createCustomView:bankLocationView andRow:1 andTitle:_L(@"title_100")];
    [_scrollView addSubview:branchView];
    
    _branchTextField = [[UITextField alloc] initWithFrame:CGRectMake(85, 12, 200, 24)];
    _branchTextField.tag = 102;
    _branchTextField.returnKeyType = UIReturnKeyDone;
    _branchTextField.font = _SYS_FONT_003;
    _branchTextField.delegate = self;
    _branchTextField.placeholder = _L(@"holder_50");
    [branchView addSubview:_branchTextField];
    
    //身份证号码View
    UIView *identityCardView = [self createCustomView:branchView andRow:1 andTitle:_L(@"title_57")];
    [_scrollView addSubview:identityCardView];
    
    _identityCardTextField = [[UITextField alloc] initWithFrame:CGRectMake(85, 12, 200, 24)];
    _identityCardTextField.tag = 97;
    _identityCardTextField.returnKeyType = UIReturnKeyDone;
    _identityCardTextField.font = _SYS_FONT_003;
    _identityCardTextField.delegate = self;
    _identityCardTextField.placeholder = _L(@"holder_21");
    [identityCardView addSubview:_identityCardTextField];
    
    //真实姓名View
    UIView *realNameView = [self createCustomView:identityCardView andRow:1 andTitle:_L(@"title_58")];
    [_scrollView addSubview:realNameView];
    
    _realNameTextField = [[UITextField alloc] initWithFrame:CGRectMake(85, 12, 200, 24)];
    _realNameTextField.tag = 96;
    _realNameTextField.returnKeyType = UIReturnKeyDone;
    _realNameTextField.font = _SYS_FONT_003;
    _realNameTextField.delegate = self;
//    _realNameTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    _realNameTextField.placeholder = _L(@"holder_22");
    [realNameView addSubview:_realNameTextField];
    
    //安全密码View
    UIView *securityPasswordView = [self createCustomView:realNameView andRow:1 andTitle:_L(@"title_59")];
    [_scrollView addSubview:securityPasswordView];
    
    _securityPasswordTextField = [[UITextField alloc] initWithFrame:CGRectMake(85, 12, 200, 24)];
    _securityPasswordTextField.tag = 95;
    _securityPasswordTextField.secureTextEntry = YES;
    _securityPasswordTextField.returnKeyType = UIReturnKeyDone;
    _securityPasswordTextField.font = _SYS_FONT_003;
    _securityPasswordTextField.delegate = self;
//    _securityPasswordTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    _securityPasswordTextField.placeholder = _L(@"holder_23");
    [securityPasswordView addSubview:_securityPasswordTextField];
    
    //验证密码View
    UIView *authPasswordView = [self createCustomView:securityPasswordView andRow:1 andTitle:_L(@"title_60")];
    [_scrollView addSubview:authPasswordView];

    _authPasswordTextField = [[UITextField alloc] initWithFrame:CGRectMake(85, 12, 200, 24)];
    _authPasswordTextField.tag = 97;
    _authPasswordTextField.secureTextEntry = YES;
    _authPasswordTextField.returnKeyType = UIReturnKeyDone;
    _authPasswordTextField.font = _SYS_FONT_003;
    _authPasswordTextField.delegate = self;
//    _authPasswordTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    _authPasswordTextField.placeholder = _L(@"holder_24");
    [authPasswordView addSubview:_authPasswordTextField];
    
    //按钮集
    
    //立即开通按钮
    UIButton *topButton = [[UIButton alloc] initWithFrame:CGRectMake(10.0f, authPasswordView.frame.origin.y + authPasswordView.frame.size.height + 50.0f , 300.0f, 44.0f)];
    [topButton setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"com_btn_006_n@2x" ofType:@"png"]] forState:UIControlStateNormal];
    [topButton setTitle:_L(@"btn_open_01") forState:UIControlStateNormal];    //充值
    [topButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    topButton.titleLabel.font = _SYS_FONT_007;
    topButton.tag = 1;
    [topButton addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
    
    [_scrollView addSubview:topButton];
    
    //以后再说按钮
    UIButton *bottomButton = [[UIButton alloc] initWithFrame:CGRectMake(10.0f, topButton.frame.origin.y + topButton.frame.size.height + 5.0f, 300.0f, 44.0f)];
    [bottomButton setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"com_btn_008_n@2x" ofType:@"png"]] forState:UIControlStateNormal];
    [bottomButton setTitle:_L(@"btn_back_02") forState:UIControlStateNormal];    //充值
    [bottomButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    bottomButton.titleLabel.font = _SYS_FONT_007;
    bottomButton.tag = 2;
    [bottomButton addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
    
    [_scrollView addSubview:bottomButton];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 私有方法

/*!
 @method
 @abstract 创建一个自定义背景及边框的view，另外包含一个Label
 @param behindView 表示创建出来的自定义view在behindView的下面
 @param row 此view有多高，当row=1时，高为40.0f，当row=2时，高为80.0f
 @param title 内置Label的text
 @result 自定义view的实例
 */
- (UIView *)createCustomView:(UIView *)behindView andRow:(NSInteger)row andTitle:(NSString *)title
{
    UIView *reslutView = nil;
    
    //设置此view在behindView的后面
    if (behindView == nil) {
        
        if (row == 1) {
            reslutView = [[UIView alloc] initWithFrame:CGRectMake(10, 5.0f, 300, 40)];
        }else if(row == 2){
            reslutView = [[UIView alloc] initWithFrame:CGRectMake(10, 5.0f, 300, 80)];
        }
        
    }else{
        if (row == 1) {
            reslutView = [[UIView alloc] initWithFrame:CGRectMake(10, behindView.frame.origin.y + behindView.frame.size.height + 5.0f, 300, 40)];
        }else if(row == 2){
            reslutView = [[UIView alloc] initWithFrame:CGRectMake(10, behindView.frame.origin.y + behindView.frame.size.height + 5.0f, 300, 80)];
        }
    }
    
    reslutView.backgroundColor = [UIColor whiteColor];
    
    //设置view的边框
    reslutView.layer.cornerRadius = 3;
    reslutView.layer.borderWidth = 1;
    reslutView.layer.borderColor = [_SYS_COLOR_003 CGColor];
    
    //title Label
    UILabel* titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10.0f, 75, 20)];
    titleLabel.text = title;
    titleLabel.font = _SYS_FONT_003;
    
    [reslutView addSubview:titleLabel];
    
    return reslutView;
}

#pragma mark - 私有方法

/*!
 @abstract 向服务器请求开通转账业务
 */
- (void)TransferOpenRequest
{
    JSONRequest* request = [[JSONRequest alloc] initWithURLString:_JSON_URL_ACCOUNT_TRANSFER_OPEN];
    request.hudOn = true;
    request.delegate = self;
    request.hudTitle = _L(@"title_loading_13");
    
    [request setValue:_passwordTextField.text           forParameter:@"password"];          //登录密码
    [request setValue:_cardIdTextField.text             forParameter:@"bankAccount"];       //银行卡号
    [request setValue:_bankNameTextField.text           forParameter:@"bankName"];          //开户行名称
    [request setValue:_branchTextField.text             forParameter:@"subbranch"];          //开户行名称
    [request setValue:_provName                         forParameter:@"provName"];          //开户行所在地一级城市名
    [request setValue:_cityName                         forParameter:@"cityName"];          //开户行所在地二级城市名
    [request setValue:_identityCardTextField.text       forParameter:@"idCard"];            //身份证号码
    [request setValue:_realNameTextField.text           forParameter:@"realName"];          //真实姓名
    [request setValue:_securityPasswordTextField.text   forParameter:@"securityPwd"];       //安全密码
    [request setValue:_authPasswordTextField.text       forParameter:@"confirmPwd"];        //验证密码
    
    [request asynchronous];
}

/*!
 @abstract 向服务器请求农户宝支持转账业务的银行集合
 */
- (void)banksRequest
{
    JSONRequest *request = [[JSONRequest alloc] initWithURLString:_JSON_URL_ACCOUNT_TRANSFER_BANKNAME_LIST];
    
    NSDictionary* dict = [request synchronous];
    
    JMFBase* jmf = [[JMFBase alloc] initWithJSONDictionary:dict];
    
    if (jmf.status == JMStatusSucceed) {
        
        if (_banksDatasource == nil) {
            _banksDatasource = [[NSMutableArray alloc] init];
        }
        
        if (_banksDatasource.count != 0) {
            
            [_banksDatasource removeAllObjects];
        }
        
    [_banksDatasource addObjectsFromArray:(NSArray *)jmf.data];
    
    }
    else {
        
        [Helper easyShowJMFStatus:jmf];
    }
}

//是否是直辖市
- (BOOL)isMunicipalityDirectly:(NSString *)address
{
    if (address == nil) {
        
        return NO;
    }
    
    if ([MUNICIPALITY_DIRECTLY indexOfObject:address] != NSNotFound) {
        
        return YES;
    }
    
    return NO;
}


#pragma mark - 自定义事件

/*!
 @abstract 返回按钮事件
 */
- (void)backButtonEvent:(id)sender
{    
    if ([_passwordTextField.text length] == 0 &&
        [_cardIdTextField.text length] == 0 &&
        [_bankNameTextField.text length] == 0 &&
        [_bankLocationTextField.text length] == 0 &&
        [_identityCardTextField.text length] == 0 &&
        [_realNameTextField.text length] == 0 &&
        [_securityPasswordTextField.text length] == 0 &&
        [_authPasswordTextField.text length] == 0
        )
    {
        [self.navigationController dismissModalViewControllerAnimated:YES];
    }
    else {
        
        UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:nil message:_L(@"alert_94") delegate:self cancelButtonTitle:_L(@"btn_no_01") otherButtonTitles:_L(@"btn_yes_01"), nil];
        
        [alertView show];
    }
}

/*!
 @abstract 功能按钮事件
 tag=1，表明点击的是“开通转账服务”按钮；tag=2，表明点击的是“以后再说”按钮。
 */
- (void)buttonEvent:(id)sender
{
    
    UIButton *clickedButton = (UIButton *)sender;
    
    //点击了开通转账服务按钮
    if (clickedButton.tag == 1) {

        if ([_passwordTextField.text length] == 0) {
            [Helper showAlertWithTitle:@"" andMessage:_L(@"holder_18")];
            return;
        }
        else if ([_cardIdTextField.text length] == 0) {
            [Helper showAlertWithTitle:@"" andMessage:_L(@"holder_51")];
            return;
        }
        else if ([_bankNameTextField.text length] == 0) {
            [Helper showAlertWithTitle:@"" andMessage:_L(@"holder_52")];
            return;
        }
        else if ([_bankLocationTextField.text length] == 0) {
            [Helper showAlertWithTitle:@"" andMessage:_L(@"holder_53")];
            return;
        }
        else if ([_branchTextField.text length] == 0) {
            [Helper showAlertWithTitle:@"" andMessage:_L(@"holder_50")];
            return;
        }
        else if ([_identityCardTextField.text length] == 0) {
            [Helper showAlertWithTitle:@"" andMessage:_L(@"holder_54")];
            return;
        }
        else if ([_realNameTextField.text length] == 0) {
            [Helper showAlertWithTitle:@"" andMessage:_L(@"holder_55")];
            return;
        }
        else if ([_securityPasswordTextField.text length] == 0) {
            [Helper showAlertWithTitle:@"" andMessage:_L(@"holder_56")];
            return;
        }
        else if ([_authPasswordTextField.text length] == 0) {
            [Helper showAlertWithTitle:@"" andMessage:_L(@"holder_57")];
            return;
        }
        else {
            
        }
        [self TransferOpenRequest];
    }
    
    //点击了以后再说服务
    else if (clickedButton.tag == 2) {
        
        [self.navigationController dismissModalViewControllerAnimated:YES];
    }
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [_passwordTextField resignFirstResponder];
    [_cardIdTextField resignFirstResponder];
    [_bankNameTextField resignFirstResponder];
    [_branchTextField resignFirstResponder];
    [_identityCardTextField resignFirstResponder];
    [_realNameTextField resignFirstResponder];
    [_securityPasswordTextField resignFirstResponder];
    [_authPasswordTextField resignFirstResponder];
}

#pragma mark - UITextField Delegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    textField.borderStyle = UITextBorderStyleRoundedRect;
    
    UIView *superView = [textField superview];
    
    float offset = superView.frame.origin.y + superView.frame.size.height - (self.view.frame.size.height - 246);
    NSTimeInterval animationDuration = 0.30f;
    [UIView beginAnimations:@"ResizeForKeyBoard" context:nil];
    [UIView setAnimationDuration:animationDuration];
    
    if(offset > 0)
    {
        
        _scrollView.contentOffset = CGPointMake(0.0f, offset);
    }
    
    [UIView commitAnimations];
    
    
    //点击后删除之前的PickerView
    for (UIView *view in self.view.subviews) {
        if ([view isKindOfClass:[UICustomPickerView class]]) {
            [view removeFromSuperview];
        }
    }
    
    //开户银行
    if (textField.tag == 99) {
        
        [_passwordTextField resignFirstResponder];
        [_cardIdTextField resignFirstResponder];
        [_bankLocationTextField resignFirstResponder];
        [_identityCardTextField resignFirstResponder];
        [_realNameTextField resignFirstResponder];
        [_securityPasswordTextField resignFirstResponder];
        [_authPasswordTextField resignFirstResponder];

        
        _customPickerView = [[UICustomPickerView alloc] initWithFrame:CGRectMake(0,_SYS_FRAME_HEIGHT - 260-44, 320, 260)];
        _customPickerView.delegate = self;
        _customPickerView.dataSource = self;
        
        [self.view addSubview:_customPickerView];
        
        [_customPickerView pickerShow:UICustomPickerViewNormalType];
        
        NSInteger selectedRow = [_banksDatasource indexOfObject:textField.text];
        
        if (selectedRow != NSNotFound) {
            
            [_customPickerView selectRow:selectedRow inComponent:0 animated:NO];
        }
        
        return NO;
    }
    
    if (textField.tag == 98) {
        
        [_passwordTextField resignFirstResponder];
        [_cardIdTextField resignFirstResponder];
        [_bankNameTextField resignFirstResponder];
        [_identityCardTextField resignFirstResponder];
        [_realNameTextField resignFirstResponder];
        [_securityPasswordTextField resignFirstResponder];
        [_authPasswordTextField resignFirstResponder];
        
        _customPickerView = [[UICustomPickerView alloc] initWithFrame:CGRectMake(0,_SYS_FRAME_HEIGHT - 260-44, 320, 260)];
        _customPickerView.delegate = self;
        _customPickerView.location = textField.text;
        _customPickerView.hzAreaPickerStyle = HZAreaPickerWithStateAndCity;
        _customPickerView.areaPickerOption = HZAreaPickerInitAddtionnalOption;
        [self.view addSubview:_customPickerView];
        
        [_customPickerView pickerShow:UICustomPickerViewAreaType];
        
        return NO;
    }
    return YES;
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    textField.borderStyle = UITextBorderStyleNone;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{    
    [textField resignFirstResponder];
    return YES;
}

#pragma mark - JSONRequestDelegate

- (void)requestDidLoadJSON:(NSDictionary *)dict
{
    JMFBase* jmf = [[JMFBase alloc] initWithJSONDictionary:dict];
    
    if (jmf.status == JMStatusSucceed) {
        
        //开通成功就提示一下用户，并且跳转到转账流程的首页
        [Helper showAllTextDialog:_L(@"alert_46") inView:self.view];
        
        [self.navigationController dismissModalViewControllerAnimated:YES];
    }
    else {
        [Helper easyShowJMFStatus:jmf];
    }
}

//
- (void)requestFailWithNetworkUnavailabe
{
    [Helper showAlertWithTitle:nil andMessage:_L(@"title_networkunavailabe")];
}

#pragma mark - UICustomPickerView DataSource

- (NSInteger)numberOfComponentsInUICustomPickerView:(UICustomPickerView *)customPickerView
{
    return 1;
}
- (NSInteger)customPickerView:(UICustomPickerView *)customPickerView
      numberOfRowsInComponent:(NSInteger)component
{
    return _banksDatasource.count;
}

#pragma mark - UICustomPickerView Delegate

- (NSString *)customPickerView:(UICustomPickerView *)customPickerView titleForRow:(NSInteger)row
                  forComponent:(NSInteger)component
{
    return _banksDatasource[row];
}

- (void)customPickerView:(UICustomPickerView *)customPickerView didSelectRow:(NSInteger)row
             inComponent:(NSInteger)component
{
    _bankNameTextField.text = _banksDatasource[row];
}

- (void)customPickerView:(UICustomPickerView *)customPickerView areaStringReceived:(NSString *)area
{
    NSArray *areaArray = [area componentsSeparatedByString:@" "];
    
    //如果是直辖市，那么一级城市和二级城市要一样，否则不一样。
//    if ([self isMunicipalityDirectly:areaArray[0]]) {
//        
//        _provName = areaArray[0];
//        _cityName = areaArray[0];
//        
//        _bankLocationTextField.text = _provName;
//    }
//    else {
//        
        _provName = areaArray[0];
        _cityName = @"";
        if (areaArray.count > 1) {
            
            _cityName = areaArray[1];
        }
    
        _bankLocationTextField.text = area;
//    }
}

- (void)customPickerViewDidDismiss:(UICustomPickerView *)customPickerView
{
    [_bankNameTextField resignFirstResponder];
    [_bankLocationTextField resignFirstResponder];
    
    _bankNameTextField.borderStyle = UITextBorderStyleNone;
    _bankLocationTextField.borderStyle = UITextBorderStyleNone;
}

#pragma mark - UIAlertView Delegate

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {
        
        [self.navigationController dismissModalViewControllerAnimated:YES];
    }
}
@end
